/*
 * math.c
 *
 *  Created on: Mar 14, 2011
 *      Author: Sharks group.
 */

//declare some implicit function in system.
int abs(int);
int rand(void);

//check if the two rectangles overlap
int verifyOverlapRectangle(int x11,int y11, int x12, int y12,
			int x21, int y21, int x22, int y22){
	int Dx1 = abs(x12 - x11) / 2; //get the half length of the first rectangle long side
	int Dx2 = abs(x22 - x21) / 2; //get the half length of the second rectangle long side
	int Ox1 = (x12 + x11) / 2; // the distance from rectangle 1 to 0
	int Ox2 = (x22 + x21) / 2;// the distance from rectangle 2 to 0

	int Dy1 = abs(y12 - y11) / 2;
	int Dy2 = abs(y22 - y21) / 2;
	int Oy1 = (y12 + y11) / 2;
	int Oy2 = (y22 + y21) / 2;

	int ovx = ((Dx2 + Dx1) > abs(Ox2 - Ox1)); //overlap in X
	int ovy = ((Dy2 + Dy1) > abs(Oy2 - Oy1)); //overlap in Y

	if(ovx && ovy){
		return 1;
	}
	return 0;
}

//random from 0 to limit
int random(int limit) {
	return rand() % limit;
}

//random from A to B
int random_range(int from, int limit){
	return rand()%(limit - from) + from;
}


